package cn.seaboot.admin.reverse.web;

import cn.seaboot.admin.mvc.argument.Params;
import cn.seaboot.admin.reverse.bean.CodeGroup;
import cn.seaboot.admin.reverse.service.CodeGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
* 代码类型 [t_db_code_group] Controller
* @author Mr.css on 2018-6-20
*/
@Controller
@Tag(name = "代码类型 [t_db_code_group] 管理")
@RequestMapping("db/code/group")
public class CodeGroupCtrl {

    @Resource
    private CodeGroupService dbCodeGroupService;

    /**
     * 代码类型 - 增
     *
     * @param pojo pojo
     * @return affected rows
     */
    @ResponseBody
    @Operation(description = "代码类型 [t_db_code_group] 增")
    @RequestMapping(value = "info", method = RequestMethod.POST)
    public int saveInfo(@Validated CodeGroup pojo) {
        return dbCodeGroupService.insert(pojo);
    }

    /**
     * 代码类型 - 删
     *
     * @param id id
     * @return affected rows
     */
    @ResponseBody
    @Operation(description = "代码类型 [t_db_code_group] 删")
    @RequestMapping(value = "info", method = RequestMethod.DELETE)
    public int deleteInfo(@Params String id) {
        return dbCodeGroupService.deleteById(id);
    }

    /**
     * 代码类型 - 查
     *
     * @param codeId id
     * @param groupName id
     * @return pojo
     */
    @ResponseBody
    @Operation(description = "代码类型 [t_db_code_group] 查")
    @RequestMapping(value = "info", method = RequestMethod.GET)
    public CodeGroup queryById(String groupName, String codeId) {
        return dbCodeGroupService.queryById(groupName, codeId);
    }

    /**
     * 代码类型 - 改
     *
     * @param pojo pojo
     * @return affected rows
     */
    @ResponseBody
    @Operation(description = "代码类型 [t_db_code_group] 改")
    @RequestMapping(value = "info", method = RequestMethod.PUT)
    public int updateInfo(@Validated CodeGroup pojo, @Params String id) {
        return dbCodeGroupService.updateById(pojo);
    }

    /**
     * 代码类型 - 查列表
     *
     * @param group 代码分组
     * @return 配置列表
     */
    @ResponseBody
    @Operation(description = "代码类型 [t_db_code_group] 列表查询")
    @RequestMapping(value = "list", method = RequestMethod.GET)
    public List<CodeGroup> queryList(@RequestParam String group) {
        return dbCodeGroupService.queryList(group);
    }
}
